import { createApp } from 'vue'
import App from './App.vue'
import router from './router/index'
import ElmentPlus from 'element-plus'
import * as ElIconList from '@element-plus/icons-vue'
/* 引入 Element-Plus 的样式文件 */
import 'element-plus/theme-chalk/index.css'
import locale from "element-plus/lib/locale/lang/zh-cn";


import VueViewer from "v-viewer"
import 'viewerjs/dist/viewer.css'


const app = createApp(App)
// 配置时间选择器语言：中文
app.use(ElmentPlus, { locale })

for (const name in ElIconList) {
  app.component(name, ElIconList[name])
}

// 全局过滤器
app.config.globalProperties = {
  $filters: {
    prefix(url) {
      if (url && url.startsWith('http')) {
        return url
      } else {
        url = `http://backend-api-02.newbee.ltd${url}`
        return url
      }
    },
    resetImgUrl(imgObj, imgSrc, maxErrorNum) {
      if (maxErrorNum > 0) {
        imgObj.onerror = function () {
          resetImgUrl(imgObj, imgSrc, maxErrorNum - 1)
        }
        setTimeout(function () {
          imgObj.src = imgSrc
        }, 500)
      } else {
        imgObj.onerror = null
        imgObj.src = imgSrc
      }
    }
  }
}

app.use(router)
app.use(VueViewer)

app.mount('#app');
